﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ELooker.utils;
using PureMVC.MVC.Views.Components;
using System.Runtime.InteropServices;
using System.IO;
using AxShockwaveFlashObjects;

namespace ELooker
{
    public partial class MainWindow : Form
    {
        public MainWindow()
        {
            InitializeComponent();

            this.Wpr = new FlaWndProc(this.FlashWndProc);
            this.OldWndProc = SetWindowLong(axShockwaveFlash1.Handle, GWL_WNDPROC, Wpr);
            axShockwaveFlash1.Movie = Directory.GetCurrentDirectory() + "\\../../../UIInterface\\bin-release\\UIInterface.swf";
            axShockwaveFlash1.Play();

            axShockwaveFlash1.FlashCall += new _IShockwaveFlashEvents_FlashCallEventHandler(axShockwaveFlash1_FlashCall);
        }

        protected override void OnControlAdded(ControlEventArgs e)
        {
            base.OnControlAdded(e);
        }

        #region 屏蔽FLASH右键
        private const int GWL_WNDPROC = -4;
        public delegate IntPtr FlaWndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

        private IntPtr OldWndProc = IntPtr.Zero;
        private FlaWndProc Wpr = null;

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, FlaWndProc wndProc);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern IntPtr CallWindowProc(IntPtr wndProc, IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

        private IntPtr FlashWndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam)
        {
            if (msg == 516)
                return (IntPtr)0;
            return CallWindowProc(OldWndProc, hWnd, msg, wParam, lParam);
        }
        #endregion

        private void button1_Click(object sender, EventArgs e)
        {
            axShockwaveFlash1.CallFunction("<invoke name=\"onExternalCall\" returntype=\"void\"><arguments><string>123</string></arguments></invoke>");
        }
        private void axShockwaveFlash1_FlashCall(object sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_FlashCallEvent e)
        {
            UtilsLogger.trace(sender, e.request);
        }
    }
}
